package com.wave.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.wave.common.annotation.Log;
import com.wave.common.annotation.RepeatSubmit;
import com.wave.common.core.controller.BaseController;
import com.wave.common.core.domain.PageQuery;
import com.wave.common.core.domain.R;
import com.wave.common.core.page.TableDataInfo;
import com.wave.common.core.validate.AddGroup;
import com.wave.common.core.validate.EditGroup;
import com.wave.common.enums.BusinessType;
import com.wave.common.utils.poi.ExcelUtil;
import com.wave.system.domain.bo.SysToolShelfLineBo;
import com.wave.system.domain.vo.SysToolShelfLineVo;
import com.wave.system.service.ISysToolShelfLineService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 工装架线体
 *
 * @author wave
 * @date 2024-10-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/toolShelfLine")
public class SysToolShelfLineController extends BaseController {

    private final ISysToolShelfLineService iSysToolShelfLineService;

    /**
     * 查询工装架线体列表
     */
    @SaCheckPermission("system:toolShelfLine:list")
    @GetMapping("/list")
    public TableDataInfo<SysToolShelfLineVo> list(SysToolShelfLineBo bo, PageQuery pageQuery) {
        return iSysToolShelfLineService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工装架线体列表
     */
    @SaCheckPermission("system:toolShelfLine:export")
    @Log(title = "工装架线体", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysToolShelfLineBo bo, HttpServletResponse response) {
        List<SysToolShelfLineVo> list = iSysToolShelfLineService.queryList(bo);
        ExcelUtil.exportExcel(list, "工装架线体", SysToolShelfLineVo.class, response);
    }

    /**
     * 获取工装架线体详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:toolShelfLine:query")
    @GetMapping("/{id}")
    public R<SysToolShelfLineVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSysToolShelfLineService.queryById(id));
    }

    /**
     * 新增工装架线体
     */
    @SaCheckPermission("system:toolShelfLine:add")
    @Log(title = "工装架线体", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysToolShelfLineBo bo) {
        return toAjax(iSysToolShelfLineService.insertByBo(bo));
    }

    /**
     * 修改工装架线体
     */
    @SaCheckPermission("system:toolShelfLine:edit")
    @Log(title = "工装架线体", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysToolShelfLineBo bo) {
        return toAjax(iSysToolShelfLineService.updateByBo(bo));
    }

    /**
     * 删除工装架线体
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:toolShelfLine:remove")
    @Log(title = "工装架线体", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSysToolShelfLineService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
